<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>航班信息管理</title>
    <style>

        .container{
            margin:auto;
        }
        table{
            text-align: center;
            width: 100%;
        }
        table tr td{
            border: 1px solid #E3E3E3;
            font-size: 14px;
        }
    </style>
    <link rel="stylesheet" href="/static/city/kuCity.css">
    <link rel="stylesheet" href="/static/bootstrap3/css/bootstrap.min.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/jquery.min.js"></script>
    <script type="text/javascript" src="/static/bootstrap3/js/bootstrap.min.js"></script>
    <script type="text/javascript" SRC="/static/city/kuCity.js"></script>
    <script type="text/javascript" >

        $(document).ready(function () {
            load_flight();
           load_city();
        });

    function load_flight(){
    $.ajax({
        url:"/flight/showFlights",
        type:"post",
        dataType:"json",
        data:{},
        success:function(data,state){
    var str ="<table class=\"table table-hover\"  border=\"1\"  cellspacing=\"0\" align=\"center\" text-align:center>";
        str+="<tr><td>编号</td><td>航班编号</td><td>出发地</td><td>目的地</td><td>航班日期</td><td>创建日期</td><td>修改日期</td><td>机舱类型</td>" +
             "<td colspan='2'>编辑</td></tr>";
        $.each(data,function(i,item){
                str+="<tr>";
                str+="<td>"+item.id+"</td>";
                str+="<td>"+item.flightno+"</td>";
                str+="<td>"+item.deptcity+"</td>";
                str+="<td>"+item.arrcity+"</td>";
                var flightdate=mydate(item.flightdate);
                str+="<td>"+flightdate+"</td>";
                var createdate=mydate(item.createdate);
                str+="<td>"+createdate+"</td>";
                var updatedate=mydate(item.updatedate);
                str+="<td>"+updatedate+"</td>";
                str+="<td>"
                        $.each(item.flightcabins,function (i,item) {
                            str+=item.cabinname +"&nbsp;&nbsp;";
                        });
                     "</td>";
                str+="<td>"+
                            "<input type='checkbox' value='"+item.id+"'/>"+
                            "&nbsp;&nbsp;&nbsp;&nbsp;"+
                            "<button class='btn btn-inverse' class=\"btn btn-primary btn-lg\" data-toggle=\"modal\" data-target=\"#myModal\" onclick='update($(this).val());' value='"+item.id+"'>"+
                                "修改" +
                            "</button>"+
                     "</td>";
                str+="</tr>";
                $("#list").html(str);
            });
        str+="</table>"

        }
       });
    }

    function update(id) {
        $.ajax({
            url:"/flight/showone",
            type:"post",
            dataType:"json",
            data:{
                'id':id,
            },
            success:function (data) {
                $("#ID").val(id),
                $("#mflightno").val(data.flightno);
                $("#mdeptcity").val(data.deptcity);
                $("#marrcity").val(data.arrcity);
                $("#mflightdate").val(mydate(data.flightdate));
            }
        });
    }

    function savveup() {
        $.ajax({
            url:"/flight/update",
            type:"post",
            dataType:"json",
            data:{
                'flightid':$("#ID").val(),
                'flightno':$("#mflightno").val(),
                'deptcity':$("#mdeptcity").val(),
                'arrcity':$("#marrcity").val()
            },
            success:function () {

            }
        });
    }

    function deleteAll() {
        var ids=[];
        $("input[type='checkbox']:checked").each(function () {
            ids.push($(this).val());
        });
        $.ajax({
            url:"/flight/delFlight",
            type:"post",
            dataType:"text",
            data:{
                'ids':ids,
            },
            success:function (data) {
                if (data=null){

                    load_flight();
                }else {
                    alert("删除成功");
                    load_flight();
                }

            }
        });
    }

        function mydate(var1) {
            var date = new Date(var1);
            Y = date.getFullYear() + '-';
            M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
            D = date.getDate() + ' ';
            h = date.getHours() + ':';
            m = date.getMinutes() + ':';
            s = date.getSeconds();
            return Y+M+D+h+m+s;

        }
        function hide() {
            $('#myModal').modal('hide');
            load_flight();
        }

        function hide2() {
            $('#myModal2').modal('hide');
            load_flight();
        }

        function flightcabin() {
            $.ajax({
                url:'/flight/insertFlight',
                dataType:'json',
                type:'post',
                data:{
                    'flightno':$("#mflightno2").val(),
                    'deptcity':$("#mdeptcity2").val(),
                    'arrcity':$("#marrcity2").val(),
                    'cabinnamef':$("#cabinnamef").val(),
                    'cabinpricef':$("#cabinpricef").val(),
                    'countf':$("#countf").val(),
                    'cabinnamey':$("#cabinnamey").val(),
                    'cabinpricey':$("#cabinpricey").val(),
                    'county':$("#county").val(),
                    'cabinnamee':$("#cabinnamee").val(),
                    'cabinpricee':$("#cabinpricee").val(),
                    'counte':$("#counte").val(),
                    'cabinnamer':$("#cabinnamer").val(),
                    'cabinpricer':$("#cabinpricer").val(),
                    'countr':$("#countr").val(),
                    'flightdate':$("#mflightdate2").val()
                },
                success:function (data) {

                }
            });
        }

        function load_city() {
            $("#mdeptcity").kuCity();
            $("#mdeptcity2").kuCity();
            $("#marrcity").kuCity();
            $("#marrcity2").kuCity();
        }

    </script>
</head>
<body>
<div class="top">
    <h3 align="center"> 航班信息管理 </h3>
    <div>
        <button style="width: 80px;margin-bottom: 10px" data-toggle="modal" data-target="#myModal2" class='btn btn-inverse'>添加航班</button>
        <button style="width: 65px;margin-bottom: 10px" onclick="deleteAll()" class='btn btn-inverse'>删除</button>

    </div>
</div>

<div id="list"></div>

<!-- Modal① -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">修改航班信息</h4>
            </div>
            <div class="modal-body" style="margin:0px auto" >
                <p><input type="hidden" name="ID" id="ID"/></p>
                <p>航班编号： <input type="text" name="mflightno" id="mflightno"/></p>
                <p>出发地: <input type="text" name="mdeptcity" id="mdeptcity"/></p>
                <p>目的地:<input type="text" name="marrcity" id="marrcity"/></p>
                <p>航班日期:<input type="text" name="mflightdate" id="mflightdate"/></p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" onclick="savveup();hide();">保存</button>
            </div>
        </div>
    </div>
</div>


<!-- Modal② -->
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel2">添加航班信息</h4>
            </div>
            <div class="modal-body" style="margin:0px auto">
                <p><input type="hidden" name="ID" id="ID2"/></p>
                <p>航班编号： <input type="text" name="mflightno" id="mflightno2"/></p>
                <p>出发地: <input type="text" name="mdeptcity" id="mdeptcity2"/></p>
                <p>目的地:<input type="text" name="marrcity" id="marrcity2"/></p>
                <p>航班日期:<input type="text" name="mflightdate" id="mflightdate2" class="easyui-datebox"/></p>
                <div class="slideThree">
                    <p>仓位情况:</p>
                    <p style="margin-left: 65px">
                        F:&nbsp;&nbsp;<input type="checkbox" id="cabinnamef" style="height: 25px;margin-top: 8px" value="F"/>
                        价格：&nbsp;&nbsp;<input type="number" style="height: 25px" id="cabinpricef"/>
                        座位数：<input type="number"  style="height: 25px" id="countf"/>
                    </p>

                    <p style="margin-left: 65px">
                        Y:&nbsp;&nbsp;<input type="checkbox" id="cabinnamey" style="height: 25px;margin-top: 8px" value="Y"/>
                        价格：&nbsp;&nbsp;<input type="number" style="height: 25px" id="cabinpricey"/>
                        座位数：<input type="number"  style="height: 25px" id="county"/>
                    </p>

                    <p style="margin-left: 65px">
                        E:&nbsp;&nbsp;<input type="checkbox" id="cabinnamee" style="height: 25px;margin-top: 8px" value="E"/>
                        价格：&nbsp;&nbsp;<input type="number" style="height: 25px" id="cabinpricee"/>
                        座位数：<input type="number"  style="height: 25px" id="counte"/>
                    </p>

                    <p style="margin-left: 65px">
                        R:&nbsp;&nbsp;<input type="checkbox" id="cabinnamer" style="height: 25px;margin-top: 8px" value="R"/>
                        价格：&nbsp;&nbsp;<input type="number" style="height: 25px" id="cabinpricer"/>
                        座位数：<input type="number"  style="height: 25px" id="countr"/>
                    </p>
                </div>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" onclick="flightcabin();hide2();">保存</button>
            </div>
        </div>
    </div>
</div>


</body>
</html>
